﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using eTMS.Commons;
using eTMS.Controllers;
using SystemControllers.MenusService;
using eTMS.Controllers.BoMonService;
using eTMS.Forms.ManageList;
using eTMS.Forms.Students;
using eTMS.Forms.Systems;
using eTMS.Helps;
using eTMS.Controls;
using SystemControllers;
using eTMS.Forms.Reviews;
using System.Diagnostics;

namespace eTMS
{
    public partial class FrmMain : eTMS.Controls.BaseForm
    {
        public FrmMain()
        {
            InitializeComponent();
        }
        private MenusController menusController = new MenusController();
        Dictionary<string, string> dicMapedMenus = new Dictionary<string, string>();
        Dictionary<string, string> dicMapedToolBars = new Dictionary<string, string>();
        private void AddMaped(string toolbar, string menu)
        {
            dicMapedMenus.Add(toolbar, menu);
            dicMapedToolBars.Add(menu, toolbar);
        }
        private void FrmMain_Load(object sender, EventArgs e)
        {
            AddMaped(btnLogin.Name, mnuSysLogin.Name);
            AddMaped(btnRole.Name, mnuSysRoleMan.Name);
            AddMaped(btnUser.Name, mnuSysUserMan.Name);
            AddMaped(btnStudentLop.Name, mnuStudentQuanLyLopSV.Name);
            AddMaped(btnStudentList.Name, mnuStudentDanhSachSinhVien.Name);
            AddMaped(btnStudentCheck.Name, mnuStudentDiemDanh.Name);
            AddMaped(btnScoreInput.Name, mnuScoreNhapDiemMonHocTheoLop.Name);
            AddMaped(btnScoreTongHopDiemMonHoc.Name, mnuScoreTongHopDiemMonHocTheoLop.Name);
            AddMaped(btnScoreTongHopDiemHocKy.Name, mnuScoreTongHopDiemHocKy.Name);
            /*
            BoMonController.LoadAllBoMon(false);
            string[]name=new string[]{"Nga","Lan","Thắng","Quốc","Anh","Quân","Đức","Thành","Thể","Luận","Minh","Trường","Ngân","Hiệu"};
            string[] dem = new string[] { "Thị", "Tiến", "Đình", "Thanh", "Quang", "Đức", "Mạnh", "Văn" };
            string[] Ho = new string[] { "Vũ", "Phạm", "Lê", "Nguyễn", "Trần", "Lý" };
            GiaoVienController c=new GiaoVienController();
            foreach (BoMonEntity boMonEntity in BoMonController.ListBoMonStatic)
            {
                for (int i = 0; i < 10; i++)
                {
                    Random random=new Random(DateTime.Now.Millisecond);
                    int r = random.Next(Ho.Length);
                    string st = Ho[r];
                    r = random.Next(dem.Length);
                    st +=" "+ dem[r];
                    r = random.Next(name.Length);
                    st += " " + name[r];
                    c.ResetObject();
                    c.GiaoVienObject.BoMon_ID = boMonEntity.BoMon_ID;
                    c.GiaoVienObject.HoTenGiaoVien = st;
                    c.GiaoVienObject.MaGiaoVien = boMonEntity.MaBoMon + "GV" + (i + 1);
                    c.GiaoVienObject.DiaChi = "";
                    c.GiaoVienObject.NgaySinh = "";
                    c.AddNew();
                }
            }*/

            Commons.Constants.APP_REGISTER_FILE = System.IO.Path.Combine(Application.StartupPath, Commons.Constants.APP_REGISTER_FILE);
            Commons.Constants.APP_REPORT_PART = System.Configuration.ConfigurationSettings.AppSettings["ReportPath"].Replace("~", Application.StartupPath);
            Commons.Configs.Load();

            SynMenu();
            if (!LisenceInfo.CheckRegister(Commons.Constants.APP_REGISTER_FILE))
            {
                /*Helps.frmRegister frm = new Helps.frmRegister();/
                if (frm.ShowDialog() != DialogResult.OK)
                {
                    if (Commons.LisenceInfo.IsRegister)
                    {
                        mnuHelpsDangKySyDung.Text = "Thông tin đăng ký";
                    }
                    else
                    {
                        mnuHelpsDangKySyDung.Text = "Đăng ký";
                    }
                }
                else
                {
                    mnuHelpsDangKySyDung.Text = "Đăng ký";
                }*/
            }
            else
            {
                mnuHelpsDangKySyDung.Text = "Thông tin đăng ký"; ;
            }

            lblNgayThang.Text = System.DateTime.Now.ToString(eTMS.Commons.Constants.APP_DATE_FORMAT);
            Office2007Renderer.Office2007Renderer renderer = new Office2007Renderer.Office2007Renderer();
            this.menuStrip1.Renderer = renderer;
            this.toolStripMenuSystem.Renderer = renderer;
            this.statusStrip1.Renderer = renderer;
            this.toolStripContainer1.TopToolStripPanel.Renderer = renderer;
            this.toolStripContainer1.BottomToolStripPanel.Renderer = renderer;
            this.toolStripContainer1.LeftToolStripPanel.Renderer = renderer;
            this.toolStripContainer1.RightToolStripPanel.Renderer = renderer;
            this.toolStripContainer1.ContentPanel.Renderer = renderer;
            Login();
        }
        private void AuthenMenu(ToolStripItemCollection collection, List<int> lsMenu_ID)
        {
            foreach (ToolStripItem item in collection)
            {
                if (item is ToolStripMenuItem)
                {
                    ToolStripMenuItem menuItem = (ToolStripMenuItem)item;
                    MenusEntity menusEntity = GetMenuByName(menuItem.Name);
                    if (menusEntity != null)
                    {
                        item.Enabled = UsersController.User.UserType == 0 || lsMenu_ID.Contains(menusEntity.Menu_ID);
                        item.Visible = item.Enabled;
                        if (dicMapedToolBars.ContainsKey(item.Name))
                        {
                            toolStripMenuSystem.Items[dicMapedToolBars[item.Name]].Visible = item.Enabled;
                            toolStripMenuSystem.Items[dicMapedToolBars[item.Name]].Enabled = item.Enabled;
                        }
                        AuthenMenu(menuItem.DropDownItems, lsMenu_ID);
                    }
                }
            }
            bool spr = true;
            foreach (ToolStripItem item in collection)
            {
                if (item is ToolStripMenuItem && item.Enabled)
                {
                    spr = false;
                }
                else if (item is ToolStripSeparator)
                {
                    if (spr)
                    {
                        item.Visible = false;
                    }
                    else
                    {
                        item.Visible = true;
                    }
                    spr = true;
                }
            }
        }
        private void LockMenu(bool isLocked)
        {
            mnuStudent.Enabled = !isLocked;
            mnuManList.Enabled = !isLocked;
            mnuSysUserMan.Enabled = !isLocked;
            mnuSysRoleMan.Enabled = !isLocked;
            mnuScore.Enabled = !isLocked;
            mnuFinance.Enabled = !isLocked;
            mnuExam.Enabled = !isLocked;
            mnuReview.Enabled = !isLocked;
            mnuTraining.Enabled = !isLocked;
            mnuReport.Enabled = !isLocked;
            toolStripMenuSystem.Enabled = !isLocked;

        }
        private void SynItem(ToolStripMenuItem item, MenusEntity parentItem, int Index)
        {
            MenusEntity entity = GetMenuByName(item.Name);
            if (entity == null)
            {
                menusController.ResetObject();
                menusController.MenusObject.MenuName = item.Name;
                menusController.MenusObject.MenuTitle = item.Text;
                menusController.MenusObject.MenuParent_ID = parentItem.Menu_ID;
                menusController.MenusObject.Module_ID = 1;
                menusController.MenusObject.MenuIndex = Index;
                menusController.MenusObject.Icon = "";
                menusController.MenusObject.URL = "";
                menusController.AddNew();
                entity = menusController.MenusObject;
            }
            else
            {
                menusController.MenusObject = entity;
                menusController.MenusObject.MenuTitle = item.Text;
                menusController.MenusObject.MenuParent_ID = parentItem.Menu_ID;
                menusController.MenusObject.Module_ID = 1;
                menusController.MenusObject.MenuIndex = Index;
                menusController.Update();
            }
            int index = 0;
            foreach (var downItem in item.DropDownItems)
            {
                if (downItem is ToolStripMenuItem)
                {
                    index++;
                    SynItem((ToolStripMenuItem)downItem, entity, index);
                }
            }
        }
        private MenusEntity GetMenuByName(string MenuName)
        {
            return MenusController.ListMenusStatic.Find(delegate(MenusEntity oFind) { return oFind.MenuName.Equals(MenuName); });
        }
        private bool IsContainMenu(string MenuName, ToolStripItemCollection collection)
        {
            if (collection.ContainsKey(MenuName))
            {
                return true;
            }
            foreach (ToolStripItem item in collection)
            {
                if (item is ToolStripMenuItem)
                {
                    if (IsContainMenu(MenuName, ((ToolStripMenuItem)item).DropDownItems))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        private void SynMenu()
        {
            MenusController.LoadAllMenuByModuleId(1);
            ModulesController.LoadAllModules(true);
            for (int i = 0; i < MenusController.ListMenusStatic.Count; i++)
            {
                MenusEntity menusEntity = MenusController.ListMenusStatic[i];
                if (!IsContainMenu(menusEntity.MenuName, menuStrip1.Items))
                {
                    menusController.MenusObject = menusEntity;
                    menusController.Delete();
                    i--;
                }
            }
            int index = 0;
            foreach (ToolStripMenuItem item in this.menuStrip1.Items)
            {
                index++;
                SynItem(item, new MenusEntity(), index);
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            lblGio.Text = DateTime.Now.ToString("HH:mm:ss");
            foreach (Form form in mdiTab1.Forms)
            {
                if (form is BaseForm)
                {
                    ((BaseForm)form).TimerTick();
                }
            }
        }

        private void ShowForm(Form frm)
        {
            this.mdiTab1.AddForm(frm);
        }
        private void mnuSysUserMan_Click(object sender, EventArgs e)
        {
            eTMS.Forms.Systems.FrmUsers frm = new FrmUsers();
            ShowForm(frm);
        }

        private void mnuSysRoleMan_Click(object sender, EventArgs e)
        {
            eTMS.Forms.Systems.FrmRoles frm = new FrmRoles();
            ShowForm(frm);
        }


        private void DisplayInfo()
        {
            lblDonVi.Text = Constants.APP_REGISTER_ORGANIZATION;
            if (UsersController.Isloged)
            {
                lblUser.Text = "Chào mừng:" + UsersController.User.DisplayName;
                mnuSysLogin.Text = "Đăng xuất";
                btnLogin.ToolTipText = "Đăng xuất";
            }
            else
            {
                lblUser.Text = "Chưa đăng nhập";
                mnuSysLogin.Text = "Đăng nhập";
                btnLogin.ToolTipText = "Đăng nhập";
            }
        }
        private void Login()
        {
            if (!UsersController.Isloged)
            {
                LockMenu(true);
                FrmLogin frmLogin = new FrmLogin();
                frmLogin.ShowDialog();
                LockMenu(!UsersController.Isloged);
                if (UsersController.Isloged)
                {
                    List<int> ls = UsersController.GetAssessibleMenus();
                    AuthenMenu(menuStrip1.Items, ls);
                    bool spr = true;
                    foreach (ToolStripItem item in toolStripMenuSystem.Items)
                    {
                        if (item is ToolStripButton && item.Enabled)
                        {
                            spr = false;
                        }
                        else if (item is ToolStripSeparator)
                        {
                            if (spr)
                            {
                                item.Visible = false;
                            }
                            else
                            {
                                item.Visible = true;
                            }
                            spr = true;
                        }
                    }
                }
            }
            else
            {
                if (Confirm("Bạn có thực sự muốn thoát ra không?"))
                {
                    mdiTab1.CloseAllForm();
                    UsersController.LogOut();
                    LockMenu(true);
                }
            }
            DisplayInfo();
        }
        private void mnuSysLogin_Click(object sender, EventArgs e)
        {
            Login();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            Login();
        }


        private void mnuSysExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void mnuHelpsAbout_Click(object sender, EventArgs e)
        {
            Helps.About frm = new About();
            frm.ShowDialog();
        }

        private void mnuHelpsDangKySyDung_Click(object sender, EventArgs e)
        {
            if (!Commons.LisenceInfo.IsRegister)
            {
                frmRegister frm = new frmRegister();
                if (frm.ShowDialog() != DialogResult.OK)
                {
                    if (!Commons.LisenceInfo.IsRegister)
                    {
                        mdiTab1.CloseAllForm();
                        mnuHelpsDangKySyDung.Text = "Đăng ký";
                    }
                    else
                    {
                        mnuHelpsDangKySyDung.Text = "Thông tin đăng ký";
                    }
                }
            }
            else
            {
                frmRegisterFor frm = new frmRegisterFor();
                frm.ShowDialog();
            }
        }


        private void btnInfor_Click(object sender, EventArgs e)
        {
            mnuHelpsAbout_Click(sender, e);
        }

        private void mnuHelpsHelp_Click(object sender, EventArgs e)
        {
            string fileName = System.IO.Path.Combine(Application.StartupPath, "HDSD.pdf");
            if (System.IO.File.Exists(fileName))
            {
                try
                {
                    System.Diagnostics.Process.Start(fileName);
                }
                catch
                {

                }
            }
        }

        private void btnHelp_Click(object sender, EventArgs e)
        {
            mnuHelpsHelp_Click(sender, e);
        }

        private void mnuManListHeDaoTao_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmHeDaoTao frm = new FrmHeDaoTao();
            ShowForm(frm);
        }

        private void mnuManListKhoa_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmKhoa frm = new FrmKhoa();
            ShowForm(frm);
        }

        private void mnuManListBoMon_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmBoMon frm = new FrmBoMon();
            ShowForm(frm);
        }

        private void mnuManListGiaoVien_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmGiaoVien frm = new FrmGiaoVien();
            ShowForm(frm);
        }

        private void mnuManListMonHoc_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmMonHoc frm = new FrmMonHoc();
            ShowForm(frm);
        }

        private void mnuManListNganhDaoTao_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmNganhHoc frm = new FrmNganhHoc();
            ShowForm(frm);
        }

        private void mnuManListHocKy_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmHocKy frm = new FrmHocKy();
            ShowForm(frm);
        }

        private void mnuManListNamHoc_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmNamHoc frm = new FrmNamHoc();
            ShowForm(frm);
        }

        private void mnuManListQuocGia_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmQuocGia frm = new FrmQuocGia();
            ShowForm(frm);
        }

        private void mnuManListDanToc_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmDanToc frm = new FrmDanToc();
            ShowForm(frm);
        }

        private void mnuManListTonGiao_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmTonGiao frm = new FrmTonGiao();
            ShowForm(frm);
        }

        private void mnuManListKhuVucTuyenSinh_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmKhuVuc frm = new FrmKhuVuc();
            ShowForm(frm);
        }

        private void mnuManListXepLoaiPhoThong_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmXepLoaiPhoThong frm = new FrmXepLoaiPhoThong();
            ShowForm(frm);
        }

        private void mnuManListTrangThai_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmTrangThai frm = new FrmTrangThai();
            ShowForm(frm);
        }

        private void mnuManListDanhHieuKhenThuong_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmDanhHieuKhenThuong frm = new FrmDanhHieuKhenThuong();
            ShowForm(frm);
        }

        private void mnuManListHinhThucKyLuat_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmHinhThucKyLuat frm = new FrmHinhThucKyLuat();
            ShowForm(frm);
        }

        private void mnuManListLoaiGiayTo_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmLoaiGiayTo frm = new FrmLoaiGiayTo();
            ShowForm(frm);
        }

        private void mnuManListLoaiHoSo_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmHoSo frm = new FrmHoSo();
            ShowForm(frm);
        }

        private void mnuManListTinhThanh_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmTinhThanh frm = new FrmTinhThanh();
            ShowForm(frm);
        }

        private void mnuManListQuanHuyen_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmQuanHuyen frm = new FrmQuanHuyen();
            ShowForm(frm);
        }

        private void mnuStudentSinhVienTrungTuyen_Click(object sender, EventArgs e)
        {
            eTMS.Forms.Students.FrmSinhVienTrungTuyen frm = new FrmSinhVienTrungTuyen();
            ShowForm(frm);
        }

        private void mnuStudentDanhSachSinhVien_Click(object sender, EventArgs e)
        {
            eTMS.Forms.Students.FrmSinhVienList frm = new FrmSinhVienList();
            ShowForm(frm);
        }

        private void mnuManListKhoaHoc_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmKhoaHoc frm = new FrmKhoaHoc();
            ShowForm(frm);
        }

        private void mnuStudentNhapHoc_Click(object sender, EventArgs e)
        {
            eTMS.Forms.Students.FrmNhapTruong frm = new FrmNhapTruong();
            ShowForm(frm);
        }

        private void mnuManListCacKhoanTien_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmKhoanTien frm = new FrmKhoanTien();
            ShowForm(frm);
        }

        private void mnuStudentKhoanTienNhapHoc_Click(object sender, EventArgs e)
        {
            
        }

        private void mnuStudentQuanLyLopSV_Click(object sender, EventArgs e)
        {
            eTMS.Forms.Students.FrmLop frm = new FrmLop();
            ShowForm(frm);
        }

        private void mnuStudentPhanNganhSinhVien_Click(object sender, EventArgs e)
        {
            eTMS.Forms.Students.FrmPhanNganhSinhVien frm = new FrmPhanNganhSinhVien();
            ShowForm(frm);
        }

        private void mnuScoreCongThucTinhDiem_Click(object sender, EventArgs e)
        {
            ;
        }

        private void mnuScoreLoaiDiem_Click(object sender, EventArgs e)
        {
            
        }

        private void mnuScoreNhapDiemMonHocTheoLop_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuTrainingXayDungChuongTrinhDaoTao_Click(object sender, EventArgs e)
        {
            
        }

        private void mnuScoreTongHopDiemMonHocTheoLop_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuExamQuanLyKyThi_Click(object sender, EventArgs e)
        {
          
        }

        private void mnuExamLapDanhSachThi_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuExamChiaPhong_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuScoreQuanLyDiemThi_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuStudentCapNhatQuocTich_Click(object sender, EventArgs e)
        {
            FrmCapNhatDuLieuSinhVien frm = new FrmCapNhatDuLieuSinhVien();
            frm.TableUpdate = "LyLichSinhVien";
            frm.Column_ID = "SinhVien_ID";
            frm.ColumnLink = "SinhVien_ID";
            frm.ColumnUpdate = "QuocGia_ID";
            frm.Text = "Cập nhật quốc tịch";
            frm.AddComboEditColumn("Quốc tịch", "QuocGia", "TenQuocGia", "QuocGia_ID");
            ShowForm(frm);
        }

        private void mnuStudentCapNhatDanToc_Click(object sender, EventArgs e)
        {
            FrmCapNhatDuLieuSinhVien frm = new FrmCapNhatDuLieuSinhVien();
            frm.TableUpdate = "LyLichSinhVien";
            frm.Column_ID = "SinhVien_ID";
            frm.ColumnLink = "SinhVien_ID";
            frm.ColumnUpdate = "DanToc_ID";
            frm.Text = "Cập nhật dân tộc";
            frm.AddComboEditColumn("Dân tộc", "DanToc", "TenDanToc", "DanToc_ID");
            ShowForm(frm);
        }

        private void mnuStudentCapNhatTonGiao_Click(object sender, EventArgs e)
        {
            FrmCapNhatDuLieuSinhVien frm = new FrmCapNhatDuLieuSinhVien();
            frm.TableUpdate = "LyLichSinhVien";
            frm.Column_ID = "SinhVien_ID";
            frm.ColumnLink = "SinhVien_ID";
            frm.ColumnUpdate = "TonGiao_ID";
            frm.Text = "Cập nhật tôn giáo";
            frm.AddComboEditColumn("Tôn giáo", "TonGiao", "TenTonGiao", "TonGiao_ID");
            ShowForm(frm);
        }

        private void mnuStudentCapNhatDoiTuongTS_Click(object sender, EventArgs e)
        {
            FrmCapNhatDuLieuSinhVien frm = new FrmCapNhatDuLieuSinhVien();
            frm.TableUpdate = "LyLichSinhVien";
            frm.Column_ID = "SinhVien_ID";
            frm.ColumnLink = "SinhVien_ID";
            frm.ColumnUpdate = "DoiTuongTS_ID";
            frm.Text = "Cập nhật đối tượng tuyển sinh";
            frm.AddComboEditColumn("Đối tượng tuyển sinh", "DoiTuongTS", "TenDoiTuong", "DoiTuongTS_ID");
            ShowForm(frm);
        }

        private void mnuStudentCapNhatXepLoaiPT_Click(object sender, EventArgs e)
        {
            FrmCapNhatDuLieuSinhVien frm = new FrmCapNhatDuLieuSinhVien();
            frm.TableUpdate = "LyLichSinhVien";
            frm.Column_ID = "SinhVien_ID";
            frm.ColumnLink = "SinhVien_ID";
            frm.ColumnUpdate = "XepLoaiPhoThong_ID";
            frm.Text = "Cập nhật xếp loại phổ thông";
            frm.AddComboEditColumn("Xếp loại phổ thông", "XepLoaiPhoThong", "TenXepLoaiPT", "XepLoaiPT_ID");
            ShowForm(frm);
        }

        private void mnuStudentCapNhatKhuVucTS_Click(object sender, EventArgs e)
        {
            FrmCapNhatDuLieuSinhVien frm = new FrmCapNhatDuLieuSinhVien();
            frm.TableUpdate = "LyLichSinhVien";
            frm.Column_ID = "SinhVien_ID";
            frm.ColumnLink = "SinhVien_ID";
            frm.ColumnUpdate = "KhuVuc_ID";
            frm.Text = "Cập nhật khu vực tuyển sinh";
            frm.AddComboEditColumn("Khu vực tuyển sinh", "KhuVuc", "TenKhuVuc", "KhuVuc_ID");
            ShowForm(frm);
        }

        private void mnuScoreTongHopDiemHocKy_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuStudentCapNhatTinhThanh_Click(object sender, EventArgs e)
        {
            FrmCapNhatDuLieuSinhVien frm = new FrmCapNhatDuLieuSinhVien();
            frm.TableUpdate = "LyLichSinhVien";
            frm.Column_ID = "SinhVien_ID";
            frm.ColumnLink = "SinhVien_ID";
            frm.ColumnUpdate = "TinhThanh_ID";
            frm.Text = "Cập nhật tỉnh thành sinh viên";
            frm.AddComboEditColumn("Tỉnh thành sinh viên", "TinhThanh", "TenTinhThanh", "TinhThanh_ID");
            ShowForm(frm);
        }

        private void mnuStudentQuanLyCanBoLop_Click(object sender, EventArgs e)
        {
            FrmCanBoLop frm = new FrmCanBoLop();
            ShowForm(frm);
        }

        private void mnuManListChucVuCanBoLop_Click(object sender, EventArgs e)
        {
            FrmChucVuCanBoLop frm = new FrmChucVuCanBoLop();
            ShowForm(frm);
        }

        private void mnuStudentGiayToSinhVien_Click(object sender, EventArgs e)
        {
            FrmGiayToSinhVien frm = new FrmGiayToSinhVien();
            ShowForm(frm);
        }

        private void mnuStudentDiemRenLuyen_Click(object sender, EventArgs e)
        {
            FrmCapNhatDuLieuSinhVien frm = new FrmCapNhatDuLieuSinhVien();
            frm.TableUpdate = "SinhVienHocKy";
            frm.Column_ID = "SinhVienHocKy_ID";
            frm.ColumnLink = "SinhVien_ID";
            frm.ColumnUpdate = "DiemRenLuyen";
            frm.Text = "Cập nhật điểm rèn luyện";
            frm.AddTextEditColumn("Điểm rèn luyện");
            frm.AddComBoNamHocHocKyFilter();
            ShowForm(frm);
        }

        private void mnuExamDanhSachCamThi_Click(object sender, EventArgs e)
        {
          
        }

        private void mnuFinanceDuLieuSoNo_Click(object sender, EventArgs e)
        {
            
        }

        private void mnuFinanceQuanLyNopTien_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuStudentCapNhatDoiTuongTroCap_Click(object sender, EventArgs e)
        {
            FrmCapNhatDuLieuSinhVien frm = new FrmCapNhatDuLieuSinhVien();
            frm.TableUpdate = "DoiTuongTroCap";
            frm.Column_ID = "DoiTuongTroCap_ID";
            frm.ColumnLink = "SinhVien_ID";
            frm.ColumnUpdate = "LoaiDoiTuongTroCap_ID";
            frm.Text = "Cập nhật đối tượng trợ cấp";
            frm.AddComboEditColumn("Đối tượng", "LoaiDoiTuongTroCap", "TenLoaiDoiTuong", "LoaiDoiTuongTroCap_ID");
            ShowForm(frm);
        }

        private void mnuManListLoaiDoiTuongTroCap_Click(object sender, EventArgs e)
        {
            eTMS.Forms.ManageList.FrmLoaiDoiTuongTroCap frm = new eTMS.Forms.ManageList.FrmLoaiDoiTuongTroCap();
            ShowForm(frm);
        }

        private void mnuFinanceQuanLyMienGiam_Click(object sender, EventArgs e)
        {
        }

        private void mnuFinanceQuanLyHocBong_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuFinanceQuanLyCachTinhHocBong_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuTrainingLopTinChi_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuTrainingCoSoDaoTao_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuTrainingKhuNha_Click(object sender, EventArgs e)
        {
        }

        private void mnuTrainingThuTrongTuan_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuTrainingCaHoc_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuTrainingTietHoc_Click(object sender, EventArgs e)
        {
            
        }

        private void mnuTrainingTuanHoc_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuTrainingDangKyGiangDay_Click(object sender, EventArgs e)
        {
        }

        private void mnuTrainingXepLichGiangDay_Click(object sender, EventArgs e)
        {
           
        }


        private void mnuEvalXetHocLai_Click(object sender, EventArgs e)
        {
            FrmDanhSachHocLai frm = new FrmDanhSachHocLai();
            ShowForm(frm);
        }

        private void mnuEvalXetLenLop_Click(object sender, EventArgs e)
        {
            FrmDanhSachDeNghiLuuBan frm = new FrmDanhSachDeNghiLuuBan();
            ShowForm(frm);
        }

        private void mnuEvalXetTotNghiep_Click(object sender, EventArgs e)
        {
            FrmDanhSachKhongDuocTotNghiep frm = new FrmDanhSachKhongDuocTotNghiep();
            ShowForm(frm);
        }

        private void mnuScoreNhapDiemTheoM_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuStudentDiemDanh_Click(object sender, EventArgs e)
        {
           
        }

        private void mnuAboutUpdate_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Hệ thống sẽ tự động đóng tất cả các cửa sổ lại. Bạn thực sự muốn cập nhật phần mềm?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                string dir = System.IO.Path.GetFullPath(System.Configuration.ConfigurationManager.AppSettings["UpdateEntryPoint"]);
                ProcessStartInfo startInfo = new ProcessStartInfo(dir);
                startInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(dir);
                startInfo.Arguments = "W";
                Process.Start(startInfo);
                Application.ExitThread();
                Application.Exit();
            }
        }
        private ToolStripItem FindMenuItem(string name, ToolStripItemCollection items)
        {
            if (items.ContainsKey(name))
            {
                return items[name];
            }
            foreach (ToolStripItem item in items)
            {
                if (item is ToolStripMenuItem)
                {
                    ToolStripItem found = FindMenuItem(name, ((ToolStripMenuItem)item).DropDownItems);
                    if (found != null)
                        return found;
                }
            }
            return null;
        }
        private void toolStripMenuSystem_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (dicMapedMenus.ContainsKey(e.ClickedItem.Name))
            {
                ToolStripItem item = FindMenuItem(dicMapedMenus[e.ClickedItem.Name], menuStrip1.Items);
                if (item != null && item.Enabled)
                    item.PerformClick();
            }
        }

        private void mnuManListInitData_Click(object sender, EventArgs e)
        {
            
        }

        private void mnuRPHOSO_CoCauXaHoi_Click(object sender, EventArgs e)
        {
            eTMS.Forms.Reports.FrmThongKeHSTheoCoCauXaHoi frm = new eTMS.Forms.Reports.FrmThongKeHSTheoCoCauXaHoi();
            ShowForm(frm);
        }

        private void mnuEvalInBangDiemTotNghiep_Click(object sender, EventArgs e)
        {
            eTMS.Forms.Reviews.FrmBangDiemToanKhoa frm = new eTMS.Forms.Reviews.FrmBangDiemToanKhoa();
            ShowForm(frm);

        }

        private void mnuRPQuaTrinh_NghiHoc_Click(object sender, EventArgs e)
        {
            eTMS.Forms.Reports.FrmBangKeDanhSachNghiHoc frm = new eTMS.Forms.Reports.FrmBangKeDanhSachNghiHoc();
            ShowForm(frm);
        }

        private void mnuStudentDanhSachBaoLuu_Click(object sender, EventArgs e)
        {
            
        }

        private void mnuManageListScheduProgram_Click(object sender, EventArgs e)
        {
        
        }

        private void mnuSystemTieuChi_Click(object sender, EventArgs e)
        {
            eTMS.Forms.Reviews.FrmTieuChuanXetDuyet frm = new FrmTieuChuanXetDuyet();
            ShowForm(frm);
        }


    }
}
